<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>
        人员列表
    </title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="css/main.css" media="all">
    <link rel="stylesheet" href="css/bootstrap.css">
</head>
<body>
<div class="x-nav">
            <span class="layui-breadcrumb">
              <a><cite>首页</cite></a>
              <a><cite>药品管理</cite></a>
              <a><cite>药品信息</cite></a>
            </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
       href="javascript:location.replace(location.href);" title="刷新"><i class="layui-icon"
                                                                        style="line-height:30px">ဂ</i></a>
</div>
<div class="x-body">
    <form class="layui-form x-center" action="" style="width:80%">
        <div class="layui-form-pane" style="margin-top: 15px;">
            <div class="layui-form-item">

                <div class="layui-input-inline">
                    <input type="text" id="med_ID"  placeholder="请输入药品ID" class="layui-input">
                </div>
                <div class="layui-input-inline" style="width:80px">
                    <button type="button" class="layui-btn" id="btnfindByMED_ID" ><i class="layui-icon">&#xe615;</i></button>
                </div>
                <div class="layui-input-inline">
                    <label></label>
                </div>
                <div class="layui-input-inline">
                    <input type="text" id="med_NAME" placeholder="请输入药品名称" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-input-inline" style="width:80px">
                    <button class="layui-btn" type="button" id="btnfindByMED_NAME" lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>
                </div>
            </div>
        </div>
    </form>
    <xblock>
        <button class="layui-btn" onclick="personnel_add('添加成员','personnel_add.html','1000','600')">
            <i class="layui-icon">&#xe608;</i>添加
        </button>
        <span class="x-right" style="line-height:40px">共有数据：<span class="layui-badge"><label id="med_n"></label></span> 条</span>
    </xblock>
    <table class="layui-table">
        <thead>
        <tr>

            <th>
                #
            </th>
            <th>
                药品编号
            </th>
            <th>
                药品名称
            </th>
            <th>
                库存
            </th>
            <th>
                价格
            </th>
            <th>
                操作
            </th>
        </tr>
        </thead>
        <tbody id="med_info">
        <tr>

            <td>
                4
            </td>
            <td>
                <u style="cursor:pointer" onclick="question_show()">
                    金华万府 </u>
            </td>
            <td>
                金华小区A栋
            </td>
            <td>
                2135
            </td>
            <td>
                2135
            </td>
            <td class="td-manage">
                <a title="编辑" href="javascript:;" onclick="personnel_edit('编辑','personnel_add.html','4','1000','600')"
                   class="ml-5" style="text-decoration:none">
                    <i class="layui-icon">&#xe642;</i>
                </a>
                <a title="删除" href="javascript:;" onclick="personnel_del(this,'4')"
                   style="text-decoration:none">
                    <i class="layui-icon">&#xe640;</i>
                </a>
            </td>
        </tr>
        </tbody>
    </table>

    <div id="page">
        <ul class="pagination">
            <li class="disabled"><span>&laquo;</span></li>
            <li class="active"><span>1</span></li>
            <li><a href="">&raquo;</a></li>
        </ul>
    </div>
</div>
<script src="lib/layui/layui.js" charset="utf-8"></script>
<script src="js/x-layui.js" charset="utf-8"></script>
<script>
    layui.use(['laydate', 'element', 'laypage', 'layer'], function () {
        $ = layui.jquery;//jquery
        laydate = layui.laydate;//日期插件
        lement = layui.element();//面包导航
        laypage = layui.laypage;//分页
        layer = layui.layer;//弹出层

        //以上模块根据需要引入
        layer.ready(function () { //为了layer.ext.js加载完毕再执行
            layer.photos({
                photos: '#x-img'
                //,shift: 5 //0-6的选择，指定弹出图片动画类型，默认随机
            });
        });
        medicineInfo()
        $("#btnfindByMED_ID").click(function (){
            var id = $("#med_ID").val()
            // alert(id)
            $.ajax({
                url: "/medicine/findByID?med_ID="+id,
                async:true,
                dataType: "json",
                contentType:"application/json",
                // data:{dc_ID:id},
                success:function (res){
                    if(res.state === 200) {
                        var e = res.data
                        $("#med_info").empty()
                        $("#med_info").append("<tr>")
                            .append("<td>" + 1 +"</td>")
                            .append("<td>" + e.med_ID + "</td>")
                            .append("<td>" + e.med_Name + "</td>")
                            .append("<td>" + e.med_Inventory + "</td>")
                            .append("<td>" + e.price + "</td>")
                            .append("<td>" +
                                "<button type='button' class='btn btn-primary col-md-3' onclick='personnel_edit("+e.dc_ID+")'>修改</button>"+
                                "<button type='button' class='btn btn-success col-md-3' onclick='med_del("+e.med_ID+")' value='删除'>删除</button>" +
                                "</td></tr>")
                    }
                    $("#med_n").text(1);
                }
            })
        })
        $("#btnfindByMED_NAME").click(function (){
            var name = $("#med_NAME").val()
            // alert(name)
            $.ajax({
                url:"/medicine/findByName?med_Name="+name,
                dataType:"json",
                contentType: "application/json",
                success: function (res){
                    if(res.state === 200){
                        var e = res.data
                        $("#med_info").empty()
                        $("#med_info").append("<tr>")
                            .append("<td>" + 1 +"</td>")
                            .append("<td>" + e.med_ID + "</td>")
                            .append("<td>" + e.med_Name + "</td>")
                            .append("<td>" + e.med_Inventory + "</td>")
                            .append("<td>" + e.price + "</td>")
                            .append("<td>" +
                                "<button type='button' class='btn btn-primary col-md-3' onclick='personnel_edit("+e.med_ID+")'>修改</button>"+
                                "<button type='button' class='btn btn-success col-md-3' onclick='med_del("+e.med_ID+")' value='删除'>删除</button>" +
                                "</td></tr>")
                        $("#med_n").text(1);
                    }
                }
            })
        })
    });

    function medicineInfo() {
        $.ajax({
            url: "/medicine/findAll",
            dataType: "json",
            async:true,
            success(res) {
                if (res.state === 200) {
                    var n = 0;
                    $("#med_info").empty()
                    $.each(res.data, function (i, e) {
                        n++;
                        $("#med_info").append("<tr>")
                            .append("<td>" + (i+1) +"</td>")
                            .append("<td>" + e.med_ID + "</td>")
                            .append("<td>" + e.med_Name + "</td>")
                            .append("<td>" + e.med_Inventory + "</td>")
                            .append("<td>" + e.price + "</td>")
                            .append("<td>" +
                                "<button type='button' class='btn btn-primary col-md-3' onclick='personnel_edit("+e.med_ID+")'>修改</button>"+
                                "<button type='button' class='btn btn-success col-md-3' onclick='med_del("+e.med_ID+")' value='删除'>删除</button>" +
                                "</td></tr>")

//<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal" data-whatever="@mdo">
                    })
                    $("#med_n").text(n);
                }
            }
        })
    }


    /*添加*/
    function personnel_add(title, url, w, h) {
        x_admin_show(title, url, w, h);
    }

    //编辑
    function personnel_edit(id) {
        url = "personnelmod.html?med_ID="+id;
        x_admin_show('修改', url, 1000,600);
    }

    /*删除*/
    function med_del(med_id){
        $.ajax({
            url:"/medicine/delete?med_ID="+med_id,
            dataType:"json",
            success: function (res){
                if(res.state === 200){
                    alert("删除成功")
                    location.reload()
                }
            }
        })
    }
</script>

</body>
</html>